% Chapter 2 ML estimation
% SVD metrics calculation

clc
clear all

% year = 2008
% TP_ml(1,:,:) = xlsread('D:\My Documents\CIRANO\Writing\Chapter2_2012\ch2_result_latex.xlsx', '2008TM', 'b35:i42');
% TP_ml(2,:,:) = xlsread('D:\My Documents\CIRANO\Writing\Chapter2_2012\ch2_result_latex.xlsx', '2008TM', 'l35:s42');
% TP_ml(3,:,:) = xlsread('D:\My Documents\CIRANO\Writing\Chapter2_2012\ch2_result_latex.xlsx', '2008TM', 'v35:ac42');
% TP_ml(4,:,:) = xlsread('D:\My Documents\CIRANO\Writing\Chapter2_2012\ch2_result_latex.xlsx', '2008TM', 'af35:am42');

% year = 2001 or 2006
TP_ml(1,:,:) = xlsread('D:\My Documents\CIRANO\Writing\Chapter2_2012\ch2_result_latex.xlsx', '2006TM', 't3:aa10');
TP_ml(2,:,:) = xlsread('D:\My Documents\CIRANO\Writing\Chapter2_2012\ch2_result_latex.xlsx', '2006TM', 't12:aa19');
TP_ml(3,:,:) = xlsread('D:\My Documents\CIRANO\Writing\Chapter2_2012\ch2_result_latex.xlsx', '2006TM', 't21:aa28');
TP_ml(4,:,:) = xlsread('D:\My Documents\CIRANO\Writing\Chapter2_2012\ch2_result_latex.xlsx', '2006TM', 't30:aa37');

load('D:\My Documents\CIRANO\db_mySQL\tp_2010Dec11_MR7.mat','cohTpGrp','durTpGrp','conditions','numEdges','year_list');
yr = 9;
SVD_coh_dur = zeros(length(conditions),1);
SVD_dur_ml = zeros(length(conditions),1);
SVD_coh_ml = zeros(length(conditions),1);
SVD = zeros(length(conditions),3); % columns represent coh, dur and ml results
for grp =1:length(conditions)
coh (:,:) =  cohTpGrp(grp, yr, 1:numEdges,:)/100;
dur (:,:) =  durTpGrp(grp, yr, 1:numEdges,:)/100;
ml(:,:) = TP_ml(grp,:,:);
SVD(grp,1) = mean(svd(coh-eye(numEdges)));
SVD(grp,2) = mean(svd(dur-eye(numEdges)));
SVD(grp,3) = mean(svd(ml-eye(numEdges)));
SVD_coh_dur(grp) = SVD(grp,1) - SVD(grp,2);
SVD_dur_ml(grp) = SVD(grp,2) - SVD(grp,3);
SVD_coh_ml(grp) = SVD(grp,1) - SVD(grp,3);
end


